
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 03/21/2010 07:44:05
-- Generated from EDMX file: C:\Projects\Aspen\Fdd.Aspen\Fdd.Aspen.EntityMapping\AspenEntityDataModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [Aspen];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_MemberGroup_Member]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[MemberGroup] DROP CONSTRAINT [FK_MemberGroup_Member];
GO
IF OBJECT_ID(N'[dbo].[FK_MemberGroup_Group]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[MemberGroup] DROP CONSTRAINT [FK_MemberGroup_Group];
GO
IF OBJECT_ID(N'[dbo].[FK_GroupGathering]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Gatherings] DROP CONSTRAINT [FK_GroupGathering];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Members]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Members];
GO
IF OBJECT_ID(N'[dbo].[Groups]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Groups];
GO
IF OBJECT_ID(N'[dbo].[Gatherings]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Gatherings];
GO
IF OBJECT_ID(N'[dbo].[MemberGroup]', 'U') IS NOT NULL
    DROP TABLE [dbo].[MemberGroup];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Members'
CREATE TABLE [dbo].[Members] (
    [Id] int  NOT NULL,
    [FirstName] nvarchar(40)  NOT NULL,
    [LastName] nvarchar(80)  NOT NULL,
    [BirthDate] datetime  NULL,
    [MemberDate] datetime  NOT NULL,
    [MemberEndDate] datetime  NULL,
    [Address] nvarchar(1000)  NULL,
    [Email] nvarchar(100)  NULL,
    [Phone] nvarchar(100)  NULL,
    [Mobile] nvarchar(100)  NULL
);
GO

-- Creating table 'Groups'
CREATE TABLE [dbo].[Groups] (
    [Id] int  NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Description] nvarchar(2048)  NOT NULL,
    [CreationDate] datetime  NOT NULL
);
GO

-- Creating table 'Gatherings'
CREATE TABLE [dbo].[Gatherings] (
    [Id] uniqueidentifier  NOT NULL,
    [GroupId] int  NOT NULL,
    [Title] nvarchar(256)  NOT NULL,
    [Description] nvarchar(2048)  NULL,
    [StartDateAndTime] datetime  NULL,
    [EndDateAndTime] datetime  NULL
);
GO

-- Creating table 'MemberGroup'
CREATE TABLE [dbo].[MemberGroup] (
    [Members_Id] int  NOT NULL,
    [Groups_Id] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'Members'
ALTER TABLE [dbo].[Members]
ADD CONSTRAINT [PK_Members]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Groups'
ALTER TABLE [dbo].[Groups]
ADD CONSTRAINT [PK_Groups]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Gatherings'
ALTER TABLE [dbo].[Gatherings]
ADD CONSTRAINT [PK_Gatherings]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Members_Id], [Groups_Id] in table 'MemberGroup'
ALTER TABLE [dbo].[MemberGroup]
ADD CONSTRAINT [PK_MemberGroup]
    PRIMARY KEY NONCLUSTERED ([Members_Id], [Groups_Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Members_Id] in table 'MemberGroup'
ALTER TABLE [dbo].[MemberGroup]
ADD CONSTRAINT [FK_MemberGroup_Member]
    FOREIGN KEY ([Members_Id])
    REFERENCES [dbo].[Members]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Groups_Id] in table 'MemberGroup'
ALTER TABLE [dbo].[MemberGroup]
ADD CONSTRAINT [FK_MemberGroup_Group]
    FOREIGN KEY ([Groups_Id])
    REFERENCES [dbo].[Groups]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_MemberGroup_Group'
CREATE INDEX [IX_FK_MemberGroup_Group]
ON [dbo].[MemberGroup]
    ([Groups_Id]);
GO

-- Creating foreign key on [GroupId] in table 'Gatherings'
ALTER TABLE [dbo].[Gatherings]
ADD CONSTRAINT [FK_GroupGathering]
    FOREIGN KEY ([GroupId])
    REFERENCES [dbo].[Groups]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_GroupGathering'
CREATE INDEX [IX_FK_GroupGathering]
ON [dbo].[Gatherings]
    ([GroupId]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------